package com.llp.declaresystem.controller;

import com.alibaba.druid.util.StringUtils;
import com.llp.declaresystem.domain.Result;
import com.llp.declaresystem.domain.entity.User;
import com.llp.declaresystem.service.UserService;
import org.apache.ibatis.util.MapUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * @BelongsProject: declare-system
 * @BelongsPackage: com.llp.declaresystem.controller
 * @Author: bovan
 * @Date: 2022/11/24 16:18
 * @Description:
 */
@RestController
@RequestMapping(value = "/api/user")
public class LoginController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public Result login(HttpSession session, @RequestBody User user){
        Map userInfo = userService.login(user,session);
        if(userInfo != null){
            return new Result<>(200,"登录成功",userInfo);
        }else{
            return new Result<>(400,"登录失败",null);
        }
    }
}
